package com.shangjinrong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shangjinrong.domain.BorrowerAttach;
import com.shangjinrong.domain.vo.BorrowerAttachVO;
import com.shangjinrong.mapper.BorrowerAttachMapper;
import com.shangjinrong.service.BorrowerAttachService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BorrowerAttachServiceImpl extends ServiceImpl<BorrowerAttachMapper, BorrowerAttach> implements BorrowerAttachService {

    @Override
    public List<BorrowerAttachVO> selectBorrowerAttachVoList(Long id) {
        QueryWrapper<BorrowerAttach> borrowerAttachQueryWrapper = new QueryWrapper<>();

        borrowerAttachQueryWrapper
                .eq("borrower_id", id);

        List<BorrowerAttach> borrowerAttachList = baseMapper.selectList(borrowerAttachQueryWrapper);

        ArrayList<BorrowerAttachVO> borrowerAttachVOArrayList = new ArrayList<>();


        for (BorrowerAttach borrowerAttach : borrowerAttachList) {
            BorrowerAttachVO borrowerAttachVO = new BorrowerAttachVO();

            borrowerAttachVO.setImageType(borrowerAttach.getImageType());
            borrowerAttachVO.setImageUrl(borrowerAttach.getImageUrl());

            borrowerAttachVOArrayList.add(borrowerAttachVO);
        }

        return borrowerAttachVOArrayList;
    }
}
